package com.woniuxy.movice.mq;


import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.woniuxy.movice.entity.Orders;


/*//**
 * 消息发送工具类
 * @author lxq
 * @data 2019年9月14日上午11:35:09
 */
@Component
public class Producer {
	@Autowired
	private RabbitTemplate rabbitTemplate;
	@Value("${ttl_order}")
	private String ttl_order;
	/**
	 * 发送订单消息
	 * @param order
	 */
	public void sendOrder(Orders order){
		CorrelationData correlationData=new CorrelationData();
		//设置消息ID
		correlationData.setId(order.getOnum());
		//rabbitTemplate.convertAndSend("dead-queue", order,correlationData);
		rabbitTemplate.convertAndSend("dead-queue", order, message -> {
		    MessageProperties messageProperties = message.getMessageProperties();
		    // 设置这条消息的过期时间
		    messageProperties.setExpiration(ttl_order);
		    return message;
		}, correlationData);
	}
}
